package 生产者消费者模型;

public class Producer_01 implements Runnable {
    Data data = null;

    public Producer_01(Data data) {
        this.data = data;
    }

    @Override
    public void run() {
        for (int i = 0; i < 1000; i++) {
            if (data.getDataLen() > 5) {
                try {
                    Thread.sleep(3000);
                    System.out.println("生产过剩，暂停生产");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            data.addData(i);
            System.out.println("生产者111，正在生产：" + i + "---长度为" + data.getDataLen());
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
